package com.canbot.u05.activity.presidemode.newcode.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.canbot.u05.R;
import com.canbot.u05.activity.presidemode.newcode.interfaces.IDialogBtnLisenter;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;

public abstract class NHostBaseDialog extends Dialog {
    protected IDialogBtnLisenter iDialogBtnLisenter;


    public NHostBaseDialog(Context context) {
        super(context, R.style.MyDialogStyle);

    }

    protected void showKeyBoard(EditText etRename) {
        etRename.setFocusable(true);
        etRename.setFocusableInTouchMode(true);
        etRename.requestFocus();
        InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(etRename, 0);
    }

    public void setiDialogBtnLisenter(IDialogBtnLisenter iDialogBtnLisenter) {
        this.iDialogBtnLisenter = iDialogBtnLisenter;
    }

    /**
     * 随机播放音频
     *
     * @param voices
     */
    protected void playRandomVoiceWithEmotion(String[][] voices) {
        int index = (int) (Math.random() * voices.length);
        String[] voiceWithEmotion = voices[index];
        MsgSendUtils.sendStringMsg(MsgType.PLAY_SOUND, voiceWithEmotion[0]);
        playEyeEmotion(voiceWithEmotion[1]);
    }

    /**
     * 播放眼睛表情
     *
     * @param eyeId
     */
    protected void playEyeEmotion(String eyeId) {
        MsgSendUtils.sendStringMsg(MsgType.EYE_MOTION, eyeId);
    }

    @Override
    public void show() {
        super.show();
        setDialogWindowAttr();
    }

    //设置对话框显示
    protected void setDialogWindowAttr() {
        setCanceledOnTouchOutside(true);
        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = (int) this.getContext().getResources().getDimension(R.dimen.x540);//宽高可设置具体大小
        lp.height = (int) this.getContext().getResources().getDimension(R.dimen.x300);
        this.getWindow().setAttributes(lp);
    }
}
